package run.siyuan.jdk.leetcode算法题;

/**
 * 定义两个变量用来存储最大值和最小值并设置默认值，循环数组依次比较数组中元素获取最大值和最小值
 */
public class NumberTest {

    public static void main(String[] args) {
        int[] array = {1, 2, 32, 23, 123, 123, 345};
        int maxNum = array[0];
        int minNum = array[0];
        for (int i = 1; i < array.length; i++) {
            if (maxNum < array[i]) {
                maxNum = array[i];
            }
            if (minNum > array[i]) {
                minNum = array[i];
            }
        }
        System.out.println("这个数组中的最大值为：" + maxNum + " 最小值为:" + minNum);
    }
}
